package com.apps.ftapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.apps.ftapp.model.MyCouponModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lyli on 2017/10/17.
 */

public class MyCouponAdapter extends BaseAdapter {

    private Context context;
    private List<MyCouponModel.CouponsBeanX.CouponsBean> dataList = new ArrayList<>();
    private LayoutInflater layoutInflater;


    public MyCouponAdapter(Context context, List<MyCouponModel.CouponsBeanX.CouponsBean> dataList) {
        this.context = context;
        this.dataList = dataList;
        layoutInflater = LayoutInflater.from(this.context);


    }


    public void addRes(List<MyCouponModel.CouponsBeanX.CouponsBean> data) {
        if (data != null) {
            this.dataList.clear();
            this.dataList.addAll(data);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        if (null != dataList && dataList.size() > 0) {
            return dataList.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        return dataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyCouponModel.CouponsBeanX.CouponsBean bean = dataList.get(i);
        ViewHolder viewHolder;
        if (view == null) {
            view = this.layoutInflater.inflate(R.layout.activity_my_coupon_listview_item, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.money.setText(bean.getValue() + "元");
        viewHolder.jianjie.setText(bean.getTitle());
        viewHolder.time.setText(bean.getStarttime() + "至" + bean.getEndtime());

        return view;
    }


    class ViewHolder {
        RelativeLayout youhuiquan;
        TextView money;
        TextView youhuiq;
        TextView jianjie;
        TextView time;

        public ViewHolder(View view) {
            youhuiquan = view.findViewById(R.id.youhuiquan);
            money = view.findViewById(R.id.money);
            youhuiq = view.findViewById(R.id.youhuiq);
            jianjie = view.findViewById(R.id.jianjie);
            time = view.findViewById(R.id.time);
            money = view.findViewById(R.id.money);
        }
    }

}
